package com.ksd.modules.rbac.menus.controller;

import com.ksd.common.controller.BaseController;
import com.ksd.common.core.result.R;
import com.ksd.modules.rbac.menus.entity.SysMenus;
import com.ksd.modules.rbac.menus.service.ISysRoleMenusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 角色菜单表 前端控制器
 * </p>
 *
 * @author Auto Generator
 * @since 2023-08-13
 */
@RestController
public class SysRoleMenusController  extends BaseController {

    @Autowired
    private ISysRoleMenusService sysRoleMenusService;

    /**
     * 查询菜单的信息
     * @return
     */
    @PostMapping("/sys/rolemenus/menus")
    public R<List<SysMenus>> findMenu(){
        List<SysMenus> menuList = sysRoleMenusService.findMenu();
        return R.data(menuList);
    }

    /**
     * 查询角色授权的菜单信息
     * @return
     */
    @PostMapping("/sys/rolemenus/rolemenus/{roleId}")
    public R<List<SysMenus>> findRolesMenu(@PathVariable("roleId") Long roleId){
        List<SysMenus> menuList = sysRoleMenusService.findRolesMenu(roleId);
        return R.data(menuList);
    }

    /**
     * 授权信息
     * @return
     */
    @PostMapping("/sys/rolemenus/saveRoleMenus")
    public R<Boolean> saveRoleMenus(@RequestParam("roleId") Long roleId,@RequestParam("menuIds") String menuIds){
        return R.data(sysRoleMenusService.saveRoleMenus(roleId,menuIds));
    }

}
